import Vue from "vue";
import VueRouter from "vue-router";

/**
 * 重写路由的push方法
 */
const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error => error)
}
Vue.use(VueRouter);
const routes = [
  {
    path: "/login",
    name: "Login",
    component: () => import("@/views/login.vue")
  },
  {
    path: "/",
    name: "loyout",
    component: () => import("@/components/layout.vue"),
    redirect: "home",
    children: [
      {
        path: "home",
        name: "公共空间",
        title:'公共空间',
        component: () => import("@/views/index.vue"),
        diction: ["0", "1"],
        meta: { icon: "el-icon-document-remove" }
      },
      {
        path: "private",
        name: "私人空间",
        title:'私人空间',
        component: () => import("@/views/private.vue"),
        diction: ["0", "1"],
        meta: { icon: "el-icon-s-cooperation" }
      },
      {
        path: "friends",
        name: "我的好友",
        title:'我的好友',
        component: () => import("@/views/friends.vue"),
        meta: { icon: "el-icon-user-solid" }
      },
      {
        path: "setting",
        title:'个人资料',
        component: () => import("@/views/setting.vue"),
        diction: ["0", "1"],
        meta: { icon: "el-icon-setting" },
        children:[
          {
            path: "/",
            component:()=>import("@/views/userInfo.vue")
           },
          {
            path: "userInfo",
            name: "userInfo",
            component:()=>import("@/views/userInfo.vue")
           },
           {
            path: "password",
            name: "password",
            component:()=>import("@/views/password.vue")
           },
        ]
      }
    ]
  },
  {
    path: "/sharedownload",
    name: "sharedownload",
    component: () => import("@/views/sharedownload.vue")
  }
];

const router = new VueRouter({
  routes
});

router.beforeEach(function (to, from, next) {
  window.localStorage.getItem("store")
  if (!window.localStorage.getItem("store")) {
    if (to.path !== "/login") {
      return next("/login");
    }
  }
  next();
});
export default router;
